package com.xuhai.blog19.admin.controller;

import com.xuhai.blog19.admin.entity.ArticleEntity;
import com.xuhai.blog19.admin.service.ArticleService;
import com.xuhai.blog19.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author PangJunjie
 * @Date 2023/2/8/008
 */
@RestController
@RequestMapping("/admin/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/page")
    public R page(int page, int limit, ArticleEntity article) {
        return R.ok().data(articleService.getPage(page, limit, article));
    }

    @GetMapping("/info/{articleId}")
    public R info(@PathVariable Integer articleId) {
        return R.ok().data(articleService.getById(articleId));
    }

    @PostMapping(value = {"/update", "/status"})
    public R update(@RequestBody ArticleEntity article) {
        articleService.update(article);
        return R.ok();
    }

    @DeleteMapping("/delete/{articleId}")
    public R delete(@PathVariable Integer articleId) {
        articleService.delete(articleId);
        return R.ok();
    }
}
